import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/31 14:44
 * @description 思路：每一个数都在变化前后都可以对偶数和做出贡献，那么进行判断即可
 */
public class Solution2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        int[] nums = {3, 2};
        int[][] queries = {{4,0}, {3, 0}};
        solution2.sumEvenAfterQueries(nums, queries);
    }
    public int[] sumEvenAfterQueries(int[] nums, int[][] queries) {
        int n = nums.length;
        int[] ans = new int[n];
        int contribute = 0;
        for (int num: nums) {
            contribute += num % 2 == 0 ? num : 0;
        }
        int start = 0;
        for (int[] query: queries) {
            if (nums[query[1]] % 2 == 0) {
                // 原来是偶 , 加上value后还是偶，
                if ((nums[query[1]] + query[0]) % 2 == 0) {
                    contribute += query[0];
                }else {
                    contribute -= nums[query[1]];
                }

            }else {
                // 原来是奇数, +value后变偶数，贡献要加上
                if((nums[query[1]] + query[0]) % 2 == 0) {
                    contribute += nums[query[1]] + query[0];
                }
            }
            ans[start++] = contribute;
            nums[query[1]] += query[0];
        }
        return ans;
    }
}
